package org.springframework.fusion.webscoket.service;

import java.io.IOException;
import java.util.Date;

import org.springframework.stereotype.Service;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

@Service
public class WebSocketService {

	public void send(WebSocketSession session) {
		System.out.println(session.isOpen());
		Boolean flag=true;
		while (session.isOpen() && flag) {
			flag=false;
			try {
				Thread.sleep(5000);
				session.sendMessage(new TextMessage(String.valueOf("ok:"+new Date().getTime())));
				flag=true;
			} catch (Exception e) {
				try {
					session.close();
				} catch (IOException e1) {
					e1.printStackTrace();
				}
			}
		}
	}

}
